home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / comm / net / tf02.lha / TinyFugue / tf-lib / stdlib.tf < prev    next >
Text File  |  1996-04-10  |  15KB  |  493 lines

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;;; TinyFugue - programmable mud client
  3. ;;;; Copyright (C) 1994 Ken Keys
  4. ;;;;
  5. ;;;; TinyFugue (aka "tf") is protected under the terms of the GNU
  6. ;;;; General Public License.  See the file "COPYING" for details.
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8.  
  9. ;;; $Id: stdlib.tf,v 35000.2 1995/04/22 20:42:30 hawkeye Exp $
  10.  
  11. ;;; TF macro library
  12.  
  13. ;;; DO NOT EDIT THIS FILE.
  14. ;;;
  15. ;;; Personal commands should be performed in %HOME/.tfrc; public commands
  16. ;;; for all users should be performed in %TFLIBDIR/local.tf.  This file will
  17. ;;; be replaced when tf is upgraded; %HOME/.tfrc and %TFLIBDIR/local.tf will
  18. ;;; not, so changes you make to them will not be lost.
  19.  
  20. ;;; Note: Some minor changes were applied by Sven Tegethoff for Amiga Compatibility.
  21.  
  22. ;;; This library is essential to the correct operation of TF.  It is as
  23. ;;; much a part of TF as the executable file.  It is designed so that
  24. ;;; it can be used by one or many users.
  25.  
  26. ;;; Many "hidden" macros here are named starting with "~" to minimize
  27. ;;; conflicts with the user's namespace; you should not give your own
  28. ;;; macros names beginning with "~".  Also, you probably don't want to
  29. ;;; use the -i flag in defining your personal macros, although you can.
  30.  
  31. ;;; file compression
  32.  
  33. /if ( systype() =~ "unix" ) \
  34.     /def -i COMPRESS_SUFFIX = .Z%;\
  35.     /def -i COMPRESS_READ = zcat%;\
  36. /elseif ( systype() =~ "os/2" ) \
  37.     /def -i COMPRESS_SUFFIX = .zip%;\
  38.     /def -i COMPRESS_READ = unzip -p%;\
  39. /endif
  40.  
  41. ;;; High priority for library hooks/triggers.  This is a hack.
  42. /set maxpri=2147483647
  43.  
  44. ;;; Commands
  45. ;; Some of these use helper macros starting with ~ to reduce conflicts with
  46. ;; the user's namespace.
  47.  
  48. ;;; /sys <command>
  49. ; Executes an "inline" shell command.
  50. ; Only works for commands that do not require input or redraw the screen.
  51.  
  52. /def -i sys = /quote -S -decho \\!!%{*-:}
  53.  
  54. ;; null commands
  55. /def -i :   = /test 1
  56. /def -i true    = /test 1
  57. /def -i false   = /test 0
  58.  
  59. ;; /world [-nlq] [<name>]
  60. ;; /world [-nlq] <host> <port>
  61.  
  62. /def -i world = /if /!@fg -s %*%; /then /@connect %*%; /endif
  63.  
  64. ;; for loop.
  65. ; syntax:  /for <var> <start> <end> <command>
  66.  
  67. /def -i for = \
  68.     /@eval \
  69.         /let %1=%2%%; \
  70.         /while ( %1 <= %3 ) \
  71.             %-3%%; \
  72.             /test %1:= %1 + 1%%; \
  73.         /done
  74.  
  75. ;; flag toggler.
  76. /def -i toggle  = /test %1 := !%1
  77.  
  78. ;; result negation.
  79. /def -i not = /@eval %*%; /test !%?
  80.  
  81. ;; expression evaluator.
  82. /def -i expr    = /@eval /echo -- $$[%*]
  83.  
  84. ;; replace text in input buffer.
  85. /def -i grab    = /test kblen() & dokey("dline")%; /input %*
  86.  
  87. ;; partial hilites.
  88. /def -i partial = /def -F -p%{hpri-0} -Ph -t"$(/escape " %*)"
  89.  
  90. ;; triggers.
  91. /def -i trig    = /trigpc 0 100 %*
  92. /def -i trigc   = /trigpc 0 %{1-x} %-1
  93. /def -i trigp   = /trigpc %{1-x} 100 %-1
  94.  
  95. /def -i undeft  = /untrig -anGgurfdhbBC0 %*
  96.  
  97. /def -i nogag = \
  98.     /if ({#}) \
  99.         /untrig -ag %*%;\
  100.     /else \
  101.         /set gag=0%;\
  102.     /endif
  103.  
  104. /def -i nohilite = \
  105.     /if ({#}) \
  106.         /untrig -aurfdhbBC0 %*%;\
  107.     /else \
  108.         /set hilite=0%;\
  109.     /endif
  110.  
  111. ;; macro existance test.
  112. /def -i ismacro = /test $(/last $(/list -s -i %{*-@}%; /echo %?))
  113.  
  114. ;; paste quoting
  115. /def -i paste   = /def -i -ag -mregexp -h"send ^.*$$" ~paste_hook = %{*-:|} %%P0
  116. /def -i endpaste    = /undef ~paste_hook
  117.  
  118. ;; other useful stuff.
  119.  
  120. /def -i first   = /echo - %1
  121. /def -i rest    = /echo - %-1
  122. /def -i last    = /echo - %L
  123. /def -i nth = /shift %1%; /echo - %1
  124.  
  125. /def -i cd  = /lcd %{*-%HOME}
  126. /def -i pwd = /last $(/lcd)
  127.  
  128. /def -i man = /help %*
  129.  
  130. /def -i signal  = /quote -S -decho !kill -%{1-l} $[getpid()]
  131.  
  132. /def -i ver = \
  133.     /test regmatch('version (.*). % Copyright', $$(/version))%; \
  134.     /echo - %P1
  135.  
  136.  
  137. ;;; Extended world definition macros
  138.  
  139. /def -i addtiny     = /addworld -T"tiny"    %*
  140. /def -i addlp       = /addworld -T"lp"  %*
  141. /def -i addlpp      = /addworld -T"lpp" %*
  142. /def -i adddiku     = /addworld -T"diku"    %*
  143. /def -i addtelnet   = /addworld -T"telnet"  %*
  144.  
  145.  
  146. ;; Auto-switch connect hook
  147. /def -iFp0 -agG -hCONNECT ~connect_switch_hook = /fg %1
  148.  
  149. ;; Proxy server connect hook
  150. /eval \
  151.     /def -iFp%{maxpri} -agG -hCONNECT proxy_hook = \
  152.         /if (proxy_host !~ "") /proxy_command%%; /endif
  153.  
  154. /def proxy_command = telnet ${world_host} ${world_port}
  155.  
  156.  
  157. ;; Heuristics to detect worlds that use prompts, but have not been classified
  158. ;; as such by the user's /addworld definition.
  159.  
  160. /def -imregexp -h'PROMPT ^([Ll]ogin: *)$' -T'^$' ~detect_worldtype_1 = \
  161.     /test prompt(P0)%; \
  162.     /addworld -Ttelnet ${world_name}%; \
  163.     /set lp=1%; \
  164.     /set always_echo=1%; \
  165.     /echo %% This looks like a telnet world, so I'll redefine it as such.%;\
  166.     /echo %% You should use the -T option of /addworld to explicitly set it yourself.
  167.  
  168. /def -imregexp -h'PROMPT ^(By what name do you wish to be known\\? *)$' -T^$ \
  169.   ~detect_worldtype_2 = \
  170.     /test prompt(P0)%; \
  171.     /addworld -Tlp ${world_name}%; \
  172.     /set lp=1%; \
  173.     /echo %% This looks like an lp-prompt world, so I'll redefine it as such.%;\
  174.     /echo %% You should use the -T option of /addworld to explicitly set it yourself.
  175.  
  176.  
  177. ;; Default worldtype hook: tiny login format (for backward compatibility),
  178. ;; but do not change any flags.
  179. /eval \
  180.     /def -mglob -T{} -hLOGIN -iFp%{maxpri} ~default_login_hook = \
  181.         /send connect $${world_character} $${world_password}
  182.  
  183. ;; Tiny hooks: login format, lp=off, always_echo=off.
  184. /eval \
  185.     /def -mglob -T{tiny|tiny.*} -hWORLD -iFp%{maxpri} ~world_hook_tiny = \
  186.         /set lp=0%%; \
  187.         /set always_echo=0%; \
  188.     /def -mglob -T{tiny|tiny.*} -hLOGIN -iFp%{maxpri} ~login_hook_tiny = \
  189.         /send connect $${world_character} $${world_password}
  190.  
  191. ;; Generic prompt-world hooks: lp=on, always_echo=off.
  192. /eval \
  193.     /def -mglob -Tprompt -hWORLD -iFp%{maxpri} ~world_hook_prompt = \
  194.         /set lp=1%%; \
  195.         /set always_echo=0
  196.  
  197. ;; LP/Diku/Aber/etc. hooks: login format, lp=on, always_echo=off.
  198. /eval \
  199.     /def -mglob -T{lp|lp.*|diku|diku.*|aber|aber.*} -hWORLD -iFp%{maxpri} \
  200.     ~world_hook_lp = \
  201.         /set lp=1%%; \
  202.         /set always_echo=0%; \
  203.     /def -mglob -T{lp|lp.*|diku|diku.*|aber|aber.*} -hLOGIN -iFp%{maxpri} \
  204.     ~login_hook_lp = \
  205.         /send -- $${world_character}%%; \
  206.         /send -- $${world_password}
  207.  
  208. ;; Hooks for LP-worlds with telnet end-of-prompt markers:
  209. ;; login format, lp=off, always_echo=off.
  210. /eval \
  211.     /def -mglob -T{lpp|lpp.*} -hWORLD -iFp%{maxpri} ~world_hook_lpp = \
  212.         /set lp=0%%; \
  213.         /set always_echo=0%; \
  214.     /def -mglob -T{lpp|lpp.*} -hLOGIN -iFp%{maxpri} ~login_hook_lpp = \
  215.         /send -- $${world_character}%%; \
  216.         /send -- $${world_password}
  217.  
  218. ;; Telnet hooks: login format, lp=on, and always_echo=on (except at
  219. ;; password prompt).
  220. /eval \
  221.     /def -mglob -Ttelnet -hWORLD -iFp%{maxpri} ~world_hook_telnet = \
  222.     /set lp=1%%; \
  223.     /set always_echo=1%; \
  224.     /def -mglob -Ttelnet -hLOGIN -iFp%{maxpri} ~login_hook_telnet = \
  225.     /send -- $${world_character}%%; \
  226.     /send -- $${world_password}%; \
  227.     /def -mregexp -Ttelnet -h'PROMPT ^Password: *$$' -iFp%{maxpri} \
  228.     ~telnet_passwd = \
  229.     /prompt %%*%%;\
  230.     /def -w$${world_name} -mglob -t* -iFn1p%{maxpri} ~echo_$${world_name} =\
  231.         /set always_echo=1%%;\
  232.     /set always_echo=0
  233.  
  234. ;; /telnet <host> [<port>]
  235. ;; Defines a telnet-world and connects to it.
  236. /def -i telnet = \
  237.     /addtelnet %{1},%{2-23} %1 %{2-23}%; \
  238.     /connect %{1},%{2-23}
  239.  
  240.  
  241. ;;; default filenames
  242. ; This is ugly, mainly to keep backward compatibility with the lame old
  243. ; "~/tiny.*" filenames and *FILE macros.  The new style, "~/*.tf", has
  244. ; a sensible suffix, and works on 8.3 FAT filesystems.  (A subdirectory
  245. ; would be nice, but then /save* would fail if the user hasn't created
  246. ; the subdirectory).
  247.  
  248. /if ( TINYPREFIX =~ "" & TINYSUFFIX =~ "" ) \
  249. ;   New-style names make more sense.
  250.     /set TINYPREFIX=%; \
  251.     /set TINYSUFFIX=.tf%; \
  252. ;   Old-style names on unix systems, for backward compatibility.
  253.     /if ( systype() =~ "unix" ) \
  254.         /set TINYPREFIX=tiny.%; \
  255.         /set TINYSUFFIX=%; \
  256.     /endif%; \
  257. /endif
  258.  
  259. /eval /def -i MACROFILE     = %{TINYPREFIX}macros%{TINYSUFFIX}
  260. /eval /def -i HILITEFILE    = %{TINYPREFIX}hilite%{TINYSUFFIX}
  261. /eval /def -i GAGFILE       = %{TINYPREFIX}gag%{TINYSUFFIX}
  262. /eval /def -i TRIGFILE      = %{TINYPREFIX}trig%{TINYSUFFIX}
  263. /eval /def -i BINDFILE      = %{TINYPREFIX}bind%{TINYSUFFIX}
  264. /eval /def -i HOOKFILE      = %{TINYPREFIX}hook%{TINYSUFFIX}
  265. /eval /def -i WORLDFILE     = %{TINYPREFIX}world%{TINYSUFFIX}
  266. /eval /def -i LOGFILE       = tiny.log
  267.  
  268.  
  269. ;;; define load* and save* macros with default filenames.
  270.  
  271. /def -i ~def_file_command = \
  272.     /def -i %1%2    = \
  273.         /%1 %%{1-$${%{3}FILE}} %{-3}
  274.  
  275. /~def_file_command  load  def     MACRO
  276. /~def_file_command  load  hilite  HILITE
  277. /~def_file_command  load  gag     GAG
  278. /~def_file_command  load  trig    TRIG
  279. /~def_file_command  load  bind    BIND
  280. /~def_file_command  load  hook    HOOK
  281. /~def_file_command  load  world   WORLD
  282.  
  283. /~def_file_command  save  def   MACRO   -mglob -h0 -b{} -t{} ?*
  284. /~def_file_command  save  gag   GAG     -mglob -h0 -b{} -t -ag
  285. /~def_file_command  save  trig  TRIG    -mglob -h0 -b{} -t -an
  286. /~def_file_command  save  bind  BIND    -mglob -h0 -b
  287. /~def_file_command  save  hook  HOOK    -mglob -h
  288.  
  289. /def -i savehilite = \
  290.     /save %{1-${HILITEFILE}} -mglob -h0 -b{} -t -aurfdhbBC0%;\
  291.     /save -a %{1-${HILITEFILE}} -mglob -h0 -b{} -t -P
  292.  
  293.  
  294. ;;; list macros
  295.  
  296. /def -i listdef     = /list %*
  297. /def -i listfullhilite  = /list -mglob -h0 -b{} -t'$(/escape ' %*)' -aurfdhbBC0
  298. /def -i listpartial = /list -mglob -h0 -b{} -t'$(/escape ' %*)' -P
  299. /def -i listhilite  = /listfullhilite%; /listpartial
  300. /def -i listgag     = /list -mglob -h0 -b{} -t'$(/escape ' %*)' -ag
  301. /def -i listtrig    = /list -mglob -h0 -b{} -t'$(/escape ' %*)' -an
  302. /def -i listbind    = /list -mglob -h0 -b'$(/escape ' %*)'
  303. /def -i listhook    = /list -mglob -h'$(/escape ' %*)'
  304.  
  305.  
  306. ;;; purge macros
  307.  
  308. /def -i purgedef    = /purge -mglob -h0 -b{} - %{1-?*}
  309. /def -i purgehilite = /purge -mglob -h0 -b{} -t'$(/escape ' %*)' -aurfdhbBC0
  310. /def -i purgegag    = /purge -mglob -h0 -b{} -t'$(/escape ' %*)' -ag
  311. /def -i purgetrig   = /purge -mglob -h0 -b{} -t'$(/escape ' %*)' -an
  312. /def -i purgedeft   = /purge -mglob -h0 -b{} -t'$(/escape ' %*)' ?*
  313. /def -i purgebind   = /purge -mglob -h0 -b'$(/escape ' %*)'
  314. /def -i purgehook   = /purge -mglob -h'$(/escape ' %*)'
  315.  
  316.  
  317. ;; library loading
  318.  
  319. /set _loaded_libs=
  320.  
  321. /def -i ~loaded = \
  322.     /if /test _loaded_libs !/ "*{%{1}}*"%; /then \
  323.         /set _loaded_libs=%{_loaded_libs} %{1}%;\
  324.     /endif
  325.  
  326. /def -i require = \
  327.     /if /test _loaded_libs !/ "*{%{1}}*"%; /then \
  328.         /load %{TFLIBDIR}/%{1}%;\
  329.     /endif
  330.  
  331. ;; meta-character quoter
  332. ;; /escape <metachars> <string>
  333. /def -i escape = \
  334.     /let meta=$[strcat({1}, "\\")]%;\
  335.     /let dest=%;\
  336.     /let tail=%-1%;\
  337.     /let i=garbage%;\
  338.     /while ((i := strchr(tail, meta)) >= 0) \
  339.         /let dest=$[strcat(dest, substr(tail,0,i), "\\", substr(tail,i,1))]%;\
  340.         /let tail=$[substr(tail, i+1)]%;\
  341.     /done%;\
  342.     /echo -- %{dest}%{tail}
  343.  
  344.  
  345. ;;; /loadhist [-lig] [-w<world>] file
  346.  
  347. /def -i loadhist = \
  348.     /let file=%L%; \
  349.     /quote -S /recordline %-L '%%{file-${LOGFILE}}
  350.  
  351. ;;; /keys simulation
  352. ;; For backward compatibilty only.
  353. ;; Supports '/keys <mnem> = <key>' and '/keys' syntax.
  354.  
  355. /def -i keys =\
  356.     /if ( {*} =/ "" ) \
  357.         /list -Ib%;\
  358.     /elseif ( {*} =/ "*,*" ) \
  359.         /echo %% The /keys comma syntax is no longer supported.%;\
  360.         /echo %% See /help bind, /help dokey.%;\
  361.     /elseif ( {*} =/ "{*} = ?*" ) \
  362.         /def -ib'%{-2}' = /dokey %1%;\
  363.     /elseif ( {*} =/ "*=*" ) \
  364.         /echo %% '=' must be surrounded by spaces.%;\
  365.         /echo %% See /help bind, /help dokey.%;\
  366.     /else \
  367.         /echo %% Bad /keys syntax.%;\
  368.     /endif
  369.  
  370.  
  371. ;;; Retry connections
  372.  
  373. ;; /retry <world> [<delay>]
  374. ;; Try to connect to <world>.  Repeat every <delay> seconds (default 60)
  375. ;; until successful.
  376.  
  377. /def -i retry = \
  378.     /def -mglob -p%{maxpri} -F -h'CONFAIL $(/escape ' %1) *' ~retry_fail_%1 =\
  379.         /repeat -%{2-60} 1 /connect %1%;\
  380.     /def -mglob -1 -p%{maxpri} -F -h'CONNECT $(/escape ' %1)' ~retry_succ_%1=\
  381.         /undef ~retry_fail_%1%;\
  382.     /connect %1
  383.  
  384. ;; /retry_off [<world>]
  385. ;; Cancels "/retry <world>" (default: all worlds)
  386.  
  387. /def -i retry_off = /purge -mglob {~retry_fail_%{1-*}|~retry_succ_%{1-*}}
  388.  
  389.  
  390. ;;; Hilites for pages and whispers
  391. ;; Simulates "/hilite page" and "/hilite whisper" in old versions.
  392.  
  393. /def -i hilite_whisper  = \
  394.   /def -ip2ah -mglob -t'{*} whispers, "*"' ~hilite_whisper1%;\
  395.   /def -ip2ah -mglob -t'{*} whispers "*"' ~hilite_whisper2
  396.  
  397. /def -i hilite_page = \
  398.   /def -ip2ah -mglob -t'{*} pages from *[,:] *' ~hilite_page1%;\
  399.   /def -ip2ah -mglob -t'You sense that {*} is looking for you in *' ~hilite_page2%;\
  400.   /def -ip2ah -mglob -t'The message was: *' ~hilite_page3%;\
  401.   /def -ip2ah -mglob -t'{*} pages[,:] *' ~hilite_page4%;\
  402.   /def -ip2ah -mglob -t'In a page-pose*' ~hilite_page5
  403.  
  404. /def -i nohilite_whisper    = /purge -mglob -I ~hilite_whisper[1-9]
  405. /def -i nohilite_page       = /purge -mglob -I ~hilite_page[1-9]
  406.  
  407.  
  408. ;;; backward compatible commands
  409.  
  410. /def -i rand = \
  411.     /if ( {#} == 0 ) /echo $[rand()]%;\
  412.     /elseif ( {#} == 1 ) /echo $[rand({1})]%;\
  413.     /elseif ( {#} == 2 ) /echo $[rand({1}, {2})]%;\
  414.     /else /echo %% rand: too many arguments%;\
  415.     /endif%;\
  416.  
  417. ; Since the default page key (TAB) is not obvious to a new user, we display
  418. ; instructions when he executes "/more on" if he hasn't re-bound the key.
  419. /def -i more = \
  420.     /if ( {*} =/ "{on|1}" & ismacro("-ib'^I' = /dokey page") ) \
  421.         /echo %% "More" paging enabled.  Use TAB to scroll.%;\
  422.     /endif%; \
  423.     /set more %*
  424.  
  425. /def -i nolog       = /log off
  426. /def -i nowrap      = /set wrap off
  427. /def -i nologin     = /set login off
  428. /def -i noquiet     = /set quiet off
  429.  
  430. /def -i act     = /trig %*
  431. /def -i reply       = /set borg %*
  432.  
  433. /def -i background  = /set background %*
  434. /def -i bamf        = /set bamf %*
  435. /def -i borg        = /set borg %*
  436. /def -i clearfull   = /set clearfull %*
  437. /def -i cleardone   = /set cleardone %*
  438. /def -i insert      = /set insert %*
  439. /def -i login       = /set login %*
  440. /def -i lp      = /set lp %*
  441. /def -i lpquote     = /set lpquote %*
  442. /def -i quiet       = /set quiet %*
  443. /def -i quitdone    = /set quitdone %*
  444. /def -i redef       = /set redef %*
  445. /def -i shpause     = /set shpause %*
  446. /def -i sockmload   = /set sockmload %*
  447. /def -i sub     = /set sub %*
  448. /def -i visual      = /set visual %*
  449.  
  450. /def -i gpri        = /set gpri %*
  451. /def -i hpri        = /set hpri %*
  452. /def -i isize       = /set isize %*
  453. /def -i ptime       = /set ptime %*
  454. /def -i wrapspace   = /set wrapspace %*
  455.  
  456. /def -i wrap = \
  457.     /if ({*} > 1) \
  458.         /set wrapsize=%*%; \
  459.         /set wrap=1%; \
  460.     /else \
  461.         /set wrap %*%;\
  462.     /endif
  463.  
  464. /def -i ~do_prefix = \
  465.     /if ( {-1} =/ "{|off|0|on|1}" ) \
  466.         /set %{1}echo %{-1}%; \
  467.     /elseif ( {-1} =/ "{all|2}" & {1} =~ "m" ) \
  468.         /set %{1}echo %{-1}%; \
  469.     /else \
  470.         /set %{1}prefix=%{-1}%; \
  471.         /set %{1}prefix%; \
  472.         /set %{1}echo=1%; \
  473.     /endif
  474.  
  475. /def -i kecho = /~do_prefix k %*
  476. /def -i mecho = /~do_prefix m %*
  477. /def -i qecho = /~do_prefix q %*
  478.  
  479. ;;; Other standard libraries
  480.  
  481. /def -hload -ag ~gagload
  482. /load kbbind.tf
  483. /load color.tf
  484. /load changes.tf
  485. /undef ~gagload
  486.  
  487. ;;; Load local public config file
  488.  
  489. /def -hloadfail -ag ~gagloadfail
  490. /eval /load %{TFLIBDIR}/local.tf
  491. /undef ~gagloadfail
  492.  
  493.